<?php

class Modules{
    

    //
    // Return list of modules and thir permisions as the forms:
    // array ('admin_users'=array('name'=>'User management','permissions'=>array('admin_users/exec_create','admin_users/exec_edit')..)
    //
    static public function get_modules_permissions(){
        global $_modules;
        include MODULE_ROOT."/modules.php";
        $modules=array();
        foreach($_modules as $m => $v){
            $class = $m."_controller";
            $controller_file=MODULE_ROOT."/$m/$class.php";
            if (file_exists($controller_file)){
                require_once $controller_file;
            }
            $methods = get_class_methods($class); // Get all actions
            $permissions=array();
            foreach ($methods as $met){
                $permissions[] = $m.'/'.$met;
            }
            $v['permissions']=$permissions;
            $modules[$m]=$v;
        }
        return $modules;
    }

    //
    // Return list of permisions as the forms:
    // array ('admin_users/exec_create'=>0,'users/exec_login'=>1,...)
    //
    static public function get_default_permissions(){
        $modules = Modules :: get_modules_permissions();
        $permissions=array();
        foreach($modules as $m => $v){
            foreach ($v['permissions'] as $per){
               $permissions[$per] = $v['default_access']; 
            }
        }
        return $permissions;
    }
    
    
}